package com.hamizhong.iflowers.web.action.admin.statics;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.IFlowerCountService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.utils.MyTools;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.FlowerCountVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;

public class AjaxQueryFlowerCountAction extends MyBaseAjaxAction {

	private IFlowerCountService iFlowerCountService = null;
	
	public IFlowerCountService getiFlowerCountService() {
		return iFlowerCountService;
	}
	public void setiFlowerCountService(IFlowerCountService iFlowerCountService) {
		this.iFlowerCountService = iFlowerCountService;
	}

	@Override
	protected JSONObject doRequest() {
		logger.info("...invoke...AjaxQueryFlowerCountAction...");
		String pageNum = getRQ().getParameter("pageNum");
		IOPResultDto<IObjectVO> resultDto = iFlowerCountService.findAll(Integer.valueOf(pageNum), MyConstants.PAGE_SIZE_COMMON_ADMIN);
		IObjectVO iObjectVO = resultDto.getFirstResult();
		List<FlowerCountVO> flowerCountVOList = iObjectVO.getFlowerCountVOList();
		int totalFlowerCountCnt = iObjectVO.getTotalFlowerCountCnt();
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject jobj = null;
		//设置总条数
		jo.put("totalCnt", totalFlowerCountCnt+"");
		//设置当前页
		jo.put("pageNum", pageNum);
		//设置总页数
		jo.put("totalPageCnt", MyTools.convertItemCnt2PageCnt(totalFlowerCountCnt, MyConstants.PAGE_SIZE_COMMON_ADMIN)+"");
		for (FlowerCountVO flowerCountVO : flowerCountVOList) {
			jobj = new JSONObject();
			jobj.put("flowerCountId", flowerCountVO.getFlowerCountId());
			jobj.put("flowerCountName", flowerCountVO.getFlowerCountName());
			jobj.put("sortId", flowerCountVO.getSortId());
			jobj.put("remarks", flowerCountVO.getRemarks());
			ja.add(jobj);
		}
		jo.put("data", ja.toString());
		jo.put("result", MyConstants.AJAX_SUCCESS);
		return jo;
	}

}
